package com.agile.leetcode.serializable;

import java.io.*;

/**
 * 序列化与反序列化的操作
 *
 * @Author:ChenZhangKun
 * @Date: 2021/9/27 11:47
 */
public class Client {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User user = new User();
        user.setId(1);
        user.setName("czk");
        FileOutputStream fos = new FileOutputStream("d://object.txt");
        // 包装
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(user);
        oos.flush();
        oos.close();
        // 反序列化
        FileInputStream fis = new FileInputStream("d://object.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        User user_1 = (User) ois.readObject();
        // czk
        System.out.println(user_1.getName());
    }
}
